from django.db import models


# Create your models here.


class Department(models.Model):
    name = models.CharField(max_length=20, verbose_name='姓名')

    class Meta:
        db_table = 'depar'


class User(models.Model):
    username = models.CharField(max_length=100, verbose_name='用户名')
    password = models.CharField(max_length=250, verbose_name='密码')
    authority = models.IntegerField(verbose_name='权限')
    depa = models.ForeignKey(Department, on_delete=models.CASCADE)

    # 1是超级权限,2是普通权限
    class Meta:
        db_table = 'user'


class Bcate(models.Model):
    name = models.CharField(max_length=20, verbose_name='分类名称')

    class Meta:
        db_table = 'bcate'
        verbose_name = '分类表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Book(models.Model):
    name = models.CharField(max_length=50, verbose_name='图书')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    cate = models.ForeignKey(Bcate, on_delete=models.CASCADE, verbose_name='分类ID')

    class Meta:
        db_table = 'book'
        verbose_name = '图书表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class RedisUser(models.Model):
    username = models.CharField(max_length=100, verbose_name='用户名')
    password = models.CharField(max_length=255, verbose_name='密码')
    mobile = models.CharField(max_length=11, verbose_name='手机号')

    class Meta:
        db_table = 'ruser'

    def __str__(self):
        return self.username


class News(models.Model):
    name = models.CharField(max_length=20, verbose_name='新闻名称')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价钱')
    content = models.TextField(verbose_name='描述')

    class Meta:
        db_table = 'news'
        verbose_name = '新闻表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Cate(models.Model):
    name = models.CharField(max_length=20)
    father = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='父ID')

    class Meta:
        db_table = 'cate'


class Shop(models.Model):
    name = models.CharField(max_length=20)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    stock = models.IntegerField(default=999)
    content = models.TextField()
    cate = models.ForeignKey(Cate, on_delete=models.CASCADE, verbose_name='外键ID')

    class Meta:
        db_table = 'shop'


class CateUser(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=255)
    mobile = models.CharField(max_length=11)

    class Meta:
        db_table = 'cateuser'


class Sclass(models.Model):
    name = models.CharField(max_length=20)
    type = models.IntegerField(default=1)

    class Meta:
        db_table = 'sclass'


class Couse(models.Model):
    name = models.CharField(max_length=20)
    cla = models.ForeignKey(Sclass, on_delete=models.CASCADE, related_name='couse')

    class Meta:
        db_table = 'couse'


class Cuser(models.Model):
    name = models.CharField(max_length=20)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=255)
    cla = models.ForeignKey(Sclass, on_delete=models.CASCADE)

    class Meta:
        db_table = 'cuser'


class Day13User(models.Model):
    name = models.CharField(max_length=20, verbose_name='姓名')
    username = models.CharField(max_length=100, verbose_name='账号')
    password = models.CharField(max_length=100, verbose_name='密码')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'day13user'
        verbose_name = '商家'
        verbose_name_plural = verbose_name


class Day13Shop(models.Model):
    name = models.CharField(max_length=20, verbose_name='名称')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    pic = models.ImageField(verbose_name='图片')
    user = models.ForeignKey(Day13User, on_delete=models.CASCADE,related_name='shop')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'day13shop'
        verbose_name = '商品'
        verbose_name_plural = verbose_name
